/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React from 'react';
import { ModalForm, ProFormTextArea } from '@ant-design/pro-form';
import { transferUpdate } from '@/services/Finance/approval';
import { message } from 'antd';
import { isFunction } from 'lodash';

const Index = (props: {
  queryData?: any;
  placeholder?: string;
  children: any;
  onCallBack?: any;
  submit?: Function;
  name?: string;
}) => {
  const {
    queryData,
    placeholder = '请输入原因',
    children,
    submit,
    onCallBack,
    name,
    ...rest
  } = props;

  const onSubmit = async (values: any) => {
    const apis = submit ? submit : transferUpdate;
    const { code, msg } = await apis({ ...values, ...queryData });
    if (code == 0) {
      message.success('提交成功');
      if (isFunction(onCallBack)) {
        onCallBack();
      }
      return true;
    } else {
      message.error(msg);
      return false;
    }
  };
  return (
    <ModalForm {...rest} title='填写原因' trigger={children} width={540} onFinish={onSubmit}>
      <ProFormTextArea
        name={name || 'admin_commnet'}
        placeholder={placeholder}
        rules={[{ required: true, message: '未审核通过申请原因必填' }]}
      />
    </ModalForm>
  );
};

export default Index;
